import Vue from 'vue'
import Router from 'vue-router'
import Fluorescent from '@/containers/Fluorescent_table'
import Information_Details from '@/containers/Information_Details'

Vue.use(Router)
//访问地址例如：http://zs.payree.com/bd/index.html?urls=fluorescent&id=14&operatorNo=15933527109#/fluorescent
//获取地址栏的url，从而跳转到响应的路由
function getUrls(){
  var reg = new RegExp('(^|&)' + 'urls' + '=([^&]*)(&|$)')
  let urlss = window.location.href;
  let search = urlss.split('?')[1]
  if (search){
      var r = search.substr(0).match(reg)
      if (r !== null){
        localStorage.setItem('urls',unescape(r[2]))
      }
  }
}
//获取地址栏的id，第一页获取数据需要带这个参数
function getIds(){
    var reg = new RegExp('(^|&)' + 'id' + '=([^&]*)(&|$)')
    let url = window.location.href;
    let search = url.split('?')[1]
    if (search){
        var r = search.substr(0).match(reg)
        if (r !== null){
            localStorage.setItem('ids',unescape(r[2]))
        }
    }
}
//获取地址栏的operatorNo，通道能力表需要此参数
function getLocationData(){
  var reg = new RegExp('(^|&)' + 'operatorNo' + '=([^&]*)(&|$)')
  let url = window.location.href;
  let search = url.split('?')[1]
  if (search){
      var r = search.substr(0).match(reg)
      if (r !== null){
          localStorage.setItem('operatorNo',unescape(r[2]))
      }
  }   
}
getUrls()
getIds()
getLocationData()

export default new Router({
  routes: [
    {
      path:'/',
      redirect:'/'+localStorage.getItem('urls')
    },
    {
      path: '/fluorescent',
      name: 'Fluorescent',
      component: Fluorescent,
      meta: {
        title: '荧鳞通道能力表'   // 标题设置
      },
    },
    {
      path: '/information',
      name: 'Information_Details',
      component: Information_Details,
      meta: {
        title: ''   // 标题设置
      },
    }
  ]
})
